package BLL;

import DAL.BooksTypeDao;
import DAL.ReaderTypeDao;
import Entity.BCategory;
import Entity.Category;

import java.util.List;

/**
 * @Author Chen
 * @Date 2022/1/9 9:44
 * @Version 1.0
 */
public class BasicInfoService {

    private static ReaderTypeDao readerTypeDao=null;
    private static BooksTypeDao bookTypeDao=null;
    static {
        if (bookTypeDao == null) {
            bookTypeDao = new BooksTypeDao();
        }
        if (readerTypeDao == null) {
            readerTypeDao = new ReaderTypeDao();
        }
    }
    //图书类别 增 删 改 查
    public int addBookType(Object...args){
        return bookTypeDao.addBookType(args);
    }

    public int deleteBookType(Object...args){
        return bookTypeDao.deleteBookType(args);
    }

    public int updateBookType(Object...args){
        return bookTypeDao.updateBookType(args);
    }
    public BCategory selectBookTypeId(Object... args){
        BCategory bc = bookTypeDao.selectBookTypeId(args);
        if (bc!=null){
            return bc;
        }
        System.out.println("没有该编号的图书类型！");
        return null;
    }
    public static List<BCategory> selectAllBookType(){
        List<BCategory> bookTypes = bookTypeDao.selectBookType();
        if (bookTypes!=null){
            return bookTypes;
        }
        System.out.println("系统中没有信息！");
        return null;
    }



    /**
     *  展示图书类型
     */
    public static void showAllBookType(){
        List<BCategory> bookTypes = bookTypeDao.selectBookType();

        if (bookTypes.size()!=0){
            System.out.println("ID"+"\t图书类别名称");
            for(int i=0;i<bookTypes.size();i++){
                System.out.println((i+1)+ bookTypes.get(i).toString());
            }
        }else {
            System.out.println("暂无数据！！！");
        }
    }

    //读者类别 增 删 改 查
    public static  int addReaderType(Object... args){
        return readerTypeDao.addReaderType(args);
    }

    public static int deleteReaderTypeById(Object... args){
        return readerTypeDao.deleteReaderType(args);
    }

    public  static  int updateReaderTypeById(Object... args){
        return readerTypeDao.updateReaderType(args);
    }

    public static List<Category> selectAllReaderType(){
        List<Category> readerTypes = readerTypeDao.selectAllReaderType();
        if (readerTypes!=null){
            return readerTypes;
        }
        return null;
    }

    /**
     * 展示所有读者类型信息
     */
    public static void showAllReaderType(){
        List<Category> readerTypes = readerTypeDao.selectAllReaderType();
        if (readerTypes.size()!=0){
            System.out.println("ID"+"\t读者类型名称"+"\t类型最大可借阅本数"+"\t最大借阅天数"+"\t罚金");
            for (int i=0; i<readerTypes.size(); i++){
                System.out.println((i+1)
                        +readerTypes.get(i).toString());
            }
        }else {
            System.out.println("暂无数据！！！");
        }
    }

    public static Category selectReaderTypeById(Object...args){
        Category readerType = readerTypeDao.selectReaderType(args);
        if (readerType!=null){
            return readerType;
        }
        return null;
    }



    //罚金 设置
    public int setFineByReaderType (int readerTypeId, double fine){
        int result = 0;
        Category readerType = null;
        if ((readerType = readerTypeDao.selectReaderType(readerTypeId)) != null) {
            result = readerTypeDao.updateReaderType(fine, readerTypeId);
        }
        return 0;
    }
}
